#!/usr/local/python27
# coding=utf8
from tornado.web import StaticFileHandler, os

from mock_static_plugin.handlers import ROUTER_HEADER


class MockStaticBaseHandler(StaticFileHandler):
    def initialize(self, path, default_filename=None, **kwargs):
        self.my_headers = kwargs.get(ROUTER_HEADER)
        #print self.my_headers,path

        super(MockStaticBaseHandler, self).initialize(path, default_filename)
        #print path,kwargs

    def set_headers(self):

        # sys guess
        super(MockStaticBaseHandler, self).set_headers()

        # guess by extension
        filename, file_extension = os.path.splitext(self.path)
        if file_extension == ".json":
            self.set_header("Content-Type", 'application/json')

        # user specify
        if self.my_headers:
            for key in self.my_headers:
                self.set_header(key, self.my_headers[key])
